package com.ants.modules.articleResource.service.impl;

import com.ants.modules.articleFollow.entity.ArticleFollow;
import com.ants.modules.articleFollow.mapper.ArticleFollowMapper;
import com.ants.modules.articleFollow.service.ArticleFollowService;
import com.ants.modules.articleResource.entity.ArticleResource;
import com.ants.modules.articleResource.mapper.ArticleResourceMapper;
import com.ants.modules.articleResource.service.ArticleResourceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * TODO
 * Author Chen
 * Date   2021/9/7 18:44
 */
@Service
@Slf4j
public class ArticleResourceServiceImpl extends ServiceImpl<ArticleResourceMapper, ArticleResource> implements ArticleResourceService {

    @Override
    public void saveArticleResource(List<String> articleResourceList, String articleId) {
        try {
            LambdaQueryWrapper<ArticleResource> rmlqw = new LambdaQueryWrapper<>();
            rmlqw.eq(ArticleResource::getArticleId, articleId);
            this.remove(rmlqw);
            ArticleResource articleResource = null;
            for (String url : articleResourceList) {
                articleResource = new ArticleResource();
                articleResource.setArticleId(articleId);
                articleResource.setResourceUrl(url);
                this.save(articleResource);
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }
    }
}
